/**
 * Created by jiachenpan on 16/11/18.
 */

export function isvalidUsername(str) {
   var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
   if (!myreg.test(str)) {
       return false;
   } else {
       return true;
   }
}

/* 合法uri*/
export function validateURL(textval) {
  const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return urlregex.test(textval)
}

/* 小写字母*/
export function validateLowerCase(str) {
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/* 大写字母*/
export function validateUpperCase(str) {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/* 大小写字母*/
export function validatAlphabets(str) {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/* 过滤订单当前状态 */
export function validateOrderStatus(str) {
  var obj = ''
  switch (str) {
    case 1:
      obj = '待支付'
      break
    case 2:
      obj = '已取消'
      break
    case 3:
      obj = '待成团'
      break
    case 4:
      obj = '拼团成功'
      break
    case 5:
      obj = '拼团失败'
      break
    case 6:
      obj = '退款中'
      break
    case 7:
      obj = '退款失败'
      break
    case 8:
      obj = '退款成功'
      break
    case 9:
      obj = '已分配商户'
      break
    case 10:
      obj = '已分配服务人员'
      break
    case 11:
      obj = '服务人员已上门'
      break
    case 12:
      obj = '确认订单'
      break
    case 13:
      obj = '确认开始服务'
      break
    case 14:
      obj = '确认服务结束'
      break
    case 15:
      obj = '订单完成'
      break
    default:
  }
  return obj
}

/* 过滤拼团当前状态 */
export function validateCollage(str) {
  var obj = ''
  switch (str) {
    case 1:
      obj = '待开团'
      break
    case 2:
      obj = '正在拼团'
      break
    case 3:
      obj = '拼团失败'
      break
    case 4:
      obj = '拼团成功'
      break
    case 5:
      obj = '已下架'
      break
    default:
  }
  return obj
}

/* 过滤商户列表当前状态 */
export function busniessTestStatus(str) {
  var obj = ''
  switch (str) {
    case 1:
      obj = '待审核'
      break
    case 2:
      obj = '审核成功'
      break
    case 3:
      obj = '审核失败'
      break
    case 4:
      obj = '关闭'
      break
    default:
  }
  return obj
}
// XLSX导出
import FileSaver from 'file-saver'
import XLSX from 'xlsx'

export function Excel(n) {
  /* generate workbook object from table */
  var wb = XLSX.utils.table_to_book(document.querySelector(n))
  /* get binary string as output */
  var wbout = XLSX.write(wb, {
    bookType: 'xlsx',
    bookSST: true,
    type: 'array'
  })
  try {
    FileSaver.saveAs(new Blob([wbout], {
      type: 'application/octet-stream'
    }), 'sheetjs.xlsx')
  } catch (e) {
    if (typeof console !== 'undefined') console.log(e, wbout)
  }
  return wbout
}

export function trade(n) {
  if(n === 3 || n === 4 || n === 9 || n === 10 || n === 11 || n === 12 || n === 13 || n === 14 || n === 15){
    return '支付成功'
  }else if(n === 6){
    return '退款中'
  }else if(n === 7){
    return '退款失败'
  }else if(n === 8){
    return '退款成功'
  }
}

export function payType(type) {
  if (type === 1) {
    return '支付宝'
  } else if (type === 2) {
    return '微信'
  } else if (type === 0) {
    return '其他'
  }
}
